#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int g_val;

int main()
{
  pid_t id = fork();
  if (id == 0)
  {
    g_val = 99;
    printf("子进程[%d], g_val = %d, &g_val = %p\n",getpid(), g_val, &g_val);
  }
  else if (id > 0)
  {
    sleep(3);
    printf("父进程[%d], g_val = %d, &g_val = %p\n", getpid(), g_val, &g_val);
  }
  else {
    perror("fork失败");
    exit(EXIT_FAILURE);
  }
  sleep(1);
  return 0;

}
